<%@ page language="java" import="java.util.*,com.biz.model.common.SessionInfo,com.biz.utils.ConfigUtil" pageEncoding="utf-8"%>
<%
	SessionInfo info = (SessionInfo) session.getAttribute(ConfigUtil.getSessionInfoName());
			
%>
<!-- 导航开始 -->
<div class="am-cf admin-main">
  <!-- sidebar start -->
  <div class="admin-sidebar am-offcanvas" id="admin-offcanvas">
    <div class="admin-offcanvas-bar">
      <ul class="am-list admin-sidebar-list" id="cont">
        <li><a href="${pageContext.request.contextPath}/jsp/main/index.jsp"><span class="am-icon-home"></span> 首页</a></li>
        
      </ul>
    </div>
  	
  </div>
  <div>
  </div>
 
<!-- 导航结束 -->
</body>
 <script language="javascript">
     //数据
     var jsonData =<%=info.getMenus()%>;
     var activityMenuId = "<%=info.getActivityMenuId()%>";
     var isWeixinMenu = window.location.href.indexOf("/jsp/menu/index.jsp") > -1;
     var activtyPid="no";
//      alert(activityMenuId);
     //主方法，运用递归实现无极层级
     function createTree(jsons,pid){
         if(jsons != null){
         	 var ul='';
             for(var i=0;i<jsons.length;i++){
                 if(jsons[i].pid == pid){
 					if(jsons[i].id == activityMenuId && !isWeixinMenu)
                    {
                 		ul+='<li style="background:#A4D3EE;">';
                 	}else{
                 		ul+='<li >';
                 	}
                 	ul+="<a href='javascript:;'  onclick='menuClick(\""+jsons[i].id+"\",\""+jsons[i].href+"\",\""+jsons[i].text+"\")' ><span class=\""+jsons[i].iconCls+"\"></span> "+jsons[i].text+" <span class='am-icon-angle-right am-fr am-margin-right'></span></a>";
                  	 if(jsons[i].id == activityMenuId && !isWeixinMenu)
                    {
                    	activtyPid = jsons[i].pid;
                    	ul+='<ul class="am-list am-collapse admin-sidebar-sub am-in" id="'+"collapse-nav"+jsons[i].id+'" >';
                    	
                    }else{
                    	ul+='<ul class="am-list am-collapse admin-sidebar-sub " id="'+"collapse-nav"+jsons[i].id+'">';
                    }
                   	ul+= createTree(jsons,jsons[i].id);
                    ul+='</ul>';
                    ul+='</li>';
                 }
             }
            
        }
         return ul ;
     }
     //菜单点击事件
     function menuClick(pid,url,name){
     	if(url!="-1"){
     		//添加session
			$.ajax({
				url:'${pageContext.request.contextPath}/user/addActivityMenu.action?id='+pid,
				type : 'post',
				async: false,
				success :  function(data){
					
				}
			});
	
     		window.location.href="${pageContext.request.contextPath}/"+url+"?pagename="+name;
     	}
     	
     	$("#collapse-nav"+pid).collapse('toggle');
     }
     //加载页面时调用的方法
     $(function(){
         var ul = createTree(jsonData,0) ;
         $("#cont").append(ul) ;
         if(activtyPid != "no")
         {
         	 $("#collapse-nav"+activtyPid).collapse('toggle');
         }

     }) ;
     
 </script>

